/*
 * search_meter.h
 *
 *  Created on: 2018.07.31
 *      Author: dongjianye
 */

#ifndef _DISCOVERY_METER_H_
#define _DISCOVERY_METER_H_

#include <stdint.h>

/*
搜表算法需要协议支持，discovery_meter只完成二叉树搜表算法、修改搜索状态，供协议层使用，
单次搜索结果需其他模块完成并告知搜表事件，具体使用步骤请参考proto_mbus
*/

#define DISCOVERY_ORDER  (1)       //搜索顺序 1：从右往左  0：从左往右
#define DISCOVERY_MAX_LAYER  (10)  //最大搜索层级
#define DISCOVERY_DEBUG   (1)

typedef enum
{
    IS_SEARCHING,
    SEARCH_END,
} discovery_status;

typedef enum
{
    SEARCH_NONE,
    SEARCH_SINGLE,
    SEARCH_COLLIDE,
} discovery_response;

typedef struct
{
    discovery_status  status;
    discovery_response res;
    int  meter_nums;
    int  found_nums;
    uint8_t  wildcard[DISCOVERY_MAX_LAYER];//使用者需要根据通配符组织搜表报文
} discover_meter_event;

void  discovery_init_and_start(discover_meter_event* discover_event, int device_nums);
int   discovery_is_searching(discover_meter_event* discover_event);
void  discovery_get_none_meter(discover_meter_event* discover_event);
void  discovery_get_one_meter(discover_meter_event* discover_event);
void  discovery_meters_collide(discover_meter_event* discover_event);
void  discovery_meter_get_next_wildcard(discover_meter_event* discover_event,uint8_t next_wildcard[]);

#endif /* INCLUDE_SEARCH_METER_H_ */
